cmake_minimum_required(VERSION 3.20)
project(examples_rclcpp_wait_set)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(std_msgs REQUIRED)

include_directories(include)

add_library(talker SHARED src/talker.cpp)
target_compile_definitions(talker PRIVATE WAIT_SET_DLL)
target_link_libraries(talker PUBLIC rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
rclcpp_components_register_node(
    talker
    PLUGIN "Talker"
    EXECUTABLE wait_set_talker)

add_library(listener SHARED src/listener.cpp)
target_compile_definitions(listener PRIVATE WAIT_SET_DLL)
target_link_libraries(listener PUBLIC rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
rclcpp_components_register_node(
    listener
    PLUGIN "Listener"
    EXECUTABLE wait_set_listener)

add_executable(wait_set src/wait_set.cpp)
target_link_libraries(wait_set PRIVATE ${example_interfaces_TARGETS} rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(static_wait_set src/static_wait_set.cpp)
target_link_libraries(static_wait_set PRIVATE rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(thread_safe_wait_set src/thread_safe_wait_set.cpp)
target_link_libraries(thread_safe_wait_set PRIVATE ${example_interfaces_TARGETS} rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(wait_set_topics_and_timer src/wait_set_topics_and_timer.cpp)
target_link_libraries(wait_set_topics_and_timer PRIVATE rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(wait_set_random_order src/wait_set_random_order.cpp)
target_link_libraries(wait_set_random_order PRIVATE rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(executor_random_order src/executor_random_order.cpp)
target_link_libraries(executor_random_order PRIVATE rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(wait_set_topics_with_different_rates src/wait_set_topics_with_different_rates.cpp)
target_link_libraries(wait_set_topics_with_different_rates PRIVATE rclcpp::rclcpp ${std_msgs_TARGETS})

add_executable(wait_set_composed src/wait_set_composed.cpp)
target_link_libraries(wait_set_composed PRIVATE talker listener rclcpp::rclcpp)

install(TARGETS
    talker
    listener
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)

install(TARGETS
  wait_set
  static_wait_set
  thread_safe_wait_set
  wait_set_topics_and_timer
  wait_set_random_order
  executor_random_order
  wait_set_topics_with_different_rates
  wait_set_composed
  DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
